package com.leetcode.LeetCode精选TOP面试题;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 覃国强
 * @date 2022-06-16 16:33
 */
public class 题库_0118_杨辉三角 {

  static
  class Solution {
    public List<List<Integer>> generate(int numRows) {
      List<List<Integer>> answers = new ArrayList<>();
      if (numRows <= 0) {
        return answers;
      }
      answers.add(new ArrayList<>(Collections.singletonList(1)));
      for (int i = 1; i < numRows; ++i) {
        List<Integer> answer = new ArrayList<>();
        answer.add(1);
        for (int j = 1; j < i; ++j) {
          answer.add(answers.get(i - 1).get(j - 1) + answers.get(i - 1).get(j));
        }
        answer.add(1);
        answers.add(answer);
      }
      return answers;
    }
  }

}
